<template>
	<view v-if="goods_info.goods_name">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in goods_info.pics" :key="index" @click="perviewFn(index)">
				<image :src="item.pics_big"></image >
			</swiper-item>
			
		</swiper>
		<!-- 商品信息区域 -->
		<!-- 商品信息区域 -->
		<view class="goods-info-box" >
			<!-- 价格区域 -->
			<view class="goods-price">
				￥{{goods_info.goods_price}}
			</view>
			<!-- 主体区域 -->
			<view class="goods-item-main">
				<!-- 左侧文本 -->
				<view class="goods-item-left">
					<text>{{goods_info.goods_name}}</text>
				</view>
				<!-- 右侧收藏等 -->
				<view class="goods-item-right">
                <uni-icons type="star" size="18"></uni-icons>
				<text>收藏</text>
				</view>
				</view>
				<!-- 运费部分 -->
				<view class="yf">
					<text>快递：免运费</text>
				</view>
		</view>
		<!-- 商品介绍 -->
		<!-- 商品详情信息 -->
		<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		<!-- 商品导航 -->
		<view class="goods-detail-container">
					<uni-goods-nav class="goods_nav"  :options="options" :fill="true" :button-group="buttonGroup" @click="onClick"
						@buttonClick="buttonClick" />
				</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 商品详情对象
				goods_info:{},
				// 商品导航制作
				options: [ {
									icon: 'shop',
									text: '店铺',
									// info: 2,
									infoBackgroundColor: '#007aff',
									infoColor: "#f5f5f5"
								}, {
									icon: 'cart',
									text: '购物车',
									info: 2
								}],
								buttonGroup: [{
										text: '加入购物车',
										backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
										color: '#fff'
									},
									{
										text: '立即购买',
										backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
										color: '#fff'
									}
								],
			};
		},
		onLoad(options) {
			const goods_id=options.goods_id
			
			this.getGoodsDFn(goods_id)
		},
		methods:{
			async getGoodsDFn(goods_id){
				const res = await uni.$http.get('/api/public/v1/goods/detail',{goods_id})
				console.log(res);
				if(res.data.meta.status !== 200 ) return uni.sToast()
				// 使用字符串的 replace() 方法，为 img 标签添加行内的 style 样式，从而解决图片底部空白间隙的问题
				res.data.message.goods_introduce = res.data.message.goods_introduce.replace(/<img /g, '<img style="display:block;" ').replace(/webp/g,'jpg')
				this.goods_info = res.data.message
			},// 图片预览
		perviewFn(index){
			uni.previewImage({
			   current:index,
			   urls:this.goods_info.pics.map(x=>{return x.pics_big })
			})
		},
		//点击购物车出现的事件
		onClick(e){
		 if(e.content.text === '购物车'){
			 uni.switchTab({
			 	url:'/pages/cart/cart'
			 })
		 }	
		}
		},
		
		
	}
</script>

<style lang="scss">
swiper {
  height: 750rpx;

  image {
    width: 100%;
    height: 100%;
  }
}
// 商品详情介绍
.goods-info-box{
	padding: 10px;
	padding-left: 0;
	.goods-price{
		font-size: 18px;
		color:#C00000
		
	}
	.goods-item-main{
		margin-top: 5px;
		display: flex;
		justify-content: space-between;
		.goods-item-left{
			// width: 80%;
			font-size: 13px;
		}
		.goods-item-right{
			width: 60px;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 12px;
			color: gray;
			margin-right: 10px;
			border-left: 1px solid #efefef;
		}
		
	}
	.yf{
		margin-top: 5px;
		font-size: 12px;
		color: gray;
	}
	
	
}
.goods-detail-container {
  // 给页面外层的容器，添加 50px 的内padding，
  // 防止页面内容被底部的商品导航组件遮盖
  padding-bottom: 50px;
}

.goods_nav {
  // 为商品导航组件添加固定定位
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
}

</style>
